package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AchievementInfo;
import com.ruoyi.system.service.IAchievementInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 科技成果库Controller
 * 
 * @author ruoyi
 * @date 2025-11-10
 */
@Controller
@RequestMapping("/business/achievementInfo")
public class AchievementInfoController extends BaseController
{
    private String prefix = "business/achievementInfo";

    @Autowired
    private IAchievementInfoService achievementInfoService;

    @RequiresPermissions("business:achievementInfo:view")
    @GetMapping()
    public String achievementInfo()
    {
        return prefix + "/achievementInfo";
    }

    /**
     * 查询科技成果库列表
     */
    @RequiresPermissions("business:achievementInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AchievementInfo achievementInfo)
    {
        startPage();
        List<AchievementInfo> list = achievementInfoService.selectAchievementInfoList(achievementInfo);
        return getDataTable(list);
    }

    /**
     * 导出科技成果库列表
     */
    @RequiresPermissions("business:achievementInfo:export")
    @Log(title = "科技成果库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AchievementInfo achievementInfo)
    {
        List<AchievementInfo> list = achievementInfoService.selectAchievementInfoList(achievementInfo);
        ExcelUtil<AchievementInfo> util = new ExcelUtil<AchievementInfo>(AchievementInfo.class);
        return util.exportExcel(list, "科技成果库数据");
    }

    /**
     * 新增科技成果库
     */
    @RequiresPermissions("business:achievementInfo:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存科技成果库
     */
    @RequiresPermissions("business:achievementInfo:add")
    @Log(title = "科技成果库", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AchievementInfo achievementInfo)
    {
        return toAjax(achievementInfoService.insertAchievementInfo(achievementInfo));
    }

    /**
     * 修改科技成果库
     */
    @RequiresPermissions("business:achievementInfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AchievementInfo achievementInfo = achievementInfoService.selectAchievementInfoById(id);
        mmap.put("achievementInfo", achievementInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存科技成果库
     */
    @RequiresPermissions("business:achievementInfo:edit")
    @Log(title = "科技成果库", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AchievementInfo achievementInfo)
    {
        return toAjax(achievementInfoService.updateAchievementInfo(achievementInfo));
    }

    /**
     * 删除科技成果库
     */
    @RequiresPermissions("business:achievementInfo:remove")
    @Log(title = "科技成果库", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(achievementInfoService.deleteAchievementInfoByIds(ids));
    }
}
